/*
 * main.cpp
 *
 *  Created on: Aug 18, 2010
 *      Author: Satish
 */
#include<iostream>
#include<vector>
#include<fstream>
#include<math.h>

#include"location.h"
#include"network.h"

using namespace std;

int main(int argc,char *argv[])
{
	vector<Location> Computers;//used to represent the computers in a network

	vector<Network> Networks; //collection of all networks from the given input

	vector<Network>::iterator network;//iterator to iterate through Network collection

	Location loc;//used to represent a location in planar coordinates(x,y)
	if(argc != 2)
	{
		cout<<"wrong usage ,correct usage is ./GettingInLine <inputfile>"<<endl;
	}
	else
	{
	
		ifstream infile(argv[1]);
		int noOfComputers;
		infile>>noOfComputers;
		while(noOfComputers != 0)
		{
			for(int i = 0; i < noOfComputers; i++ )
			{
				infile>>loc;
				Computers.push_back(loc);

			}	
			//initialize a new network using the input read
			Network tempnet(noOfComputers,Computers);
			Computers.clear();
			tempnet.calculatedistances();
			Networks.push_back(tempnet);
			infile>>noOfComputers;
			if(noOfComputers != 0)
				continue;
		}

		int i=1;//used to keep track of the network number

		for(network = Networks.begin();network != Networks.end(); network++,i++)
		{
			cout<<"*****************************************************************"<<endl;
			cout<<"Network#"<<i<<endl;
			cout<<"The Computers in the network are Located at"<<endl;
		
			(*network).showcomputers();
			(*network).findoptimalpath();
			cout<<endl;
		}
	}
	return 0;
}
